
public class RGB {

	private double[] RGB;
	
	public RGB(){
		this.RGB = new double[3];
		for(int i=0;i<3;i++) 
			this.RGB[i] = 0;
		
	}
	
	public RGB(double Red, double Green, double Blue){
		this();
		this.RGB[0] = Red;
		this.RGB[1] = Green;
		this.RGB[2] = Blue;
	}
	
	public RGB(double[] RGB){
		this(RGB[0], RGB[1], RGB[2]);
	}
	
	public void setRGB(int[] scaledRGB){

		for(int i=0; i<3; i++){
			if (scaledRGB[i] < 0){
				this.RGB[i] = 0.0;
				continue;
			}
			if (scaledRGB[i] > 255){
				this.RGB[i] = 1;
				continue;
			}
			this.RGB[i] = (double)Math.round(scaledRGB[i]/255.0);
		}
	}
	
	public int getRGB(){

		int[] scaledRGB = new int[3];
		for(int i=0; i<3; i++){
			if (this.RGB[i] < 0){
				scaledRGB[i] = 0;
				continue;
			}
			if (this.RGB[i] > 1){
				scaledRGB[i] = 255;
				continue;
			}
			scaledRGB[i] = (int)Math.round(this.RGB[i]*255);
		}
		return (scaledRGB[0] << 16) | (scaledRGB[1] << 8) | scaledRGB[2] ;
	}
	
	public double[] getCoords(){
		return this.RGB;
	}
	public static RGB add(RGB v1, RGB v2){
		double[] c1 = v1.getCoords();
		double[] c2 = v2.getCoords();
		
		
		return new RGB(Math.min(c1[0] + c2[0], 1.0) , Math.min(c1[1] + c2[1],1.0) , Math.min(c1[2] + c2[2], 1.0));	
	}
	
	public RGB mul(double factor){
		return new RGB(factor*this.RGB[0] ,factor*this.RGB[1] ,factor*this.RGB[2] );
	}

	public static RGB mulRGB(RGB rgb1, RGB rgb2){
		double[] c1 = rgb1.getCoords();
		double[] c2 = rgb2.getCoords();
		for(int i=0; i<3; i++){
			if (c1[i] < 0) c1[i]=0;
			if (c2[i] < 0) c2[i]=0;
			if (c1[i] > 1) c1[i]=1;
			if (c2[i] > 1) c2[i]=1;
		}
		return new RGB(c1[0]*c2[0], c1[1]*c2[1], c1[2]*c2[2]);
	}
	

	public String toString(){
		return "(" + RGB[0] + ", " + RGB[1] + ", " + RGB[2] + ")";
	}
}


